package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.DeviceClassMode;
import com.wtwd.campus.entity.MqMessage;

import java.util.ArrayList;

public class NoDisturbTimeSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        DeviceClassMode deviceClassMode = (DeviceClassMode)mqMessage.getObject();
        String repeatTime = deviceClassMode.getRepeatTime();
        String start = deviceClassMode.getStartTime();
        String end = deviceClassMode.getEndTime();
        String imei = deviceClassMode.getImei();
        String commandNumber = deviceClassMode.getCommandNumber();
        Integer sequence = deviceClassMode.getSequence();
        Integer onOff = deviceClassMode.getOnOff();
        String parseRepeat = "";
        char[] chars = repeatTime.toCharArray();
        for(int i = 0; i < chars.length; i++){
            String day = String.valueOf(i + 1);
            parseRepeat = parseRepeat.concat(day).concat(String.valueOf(chars[i]));
        }
        String time = start.replace(":","").concat(end.replace(":","")).concat(parseRepeat);
        String content = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(Constants.SET_NO_DISTURB_TIME)
                .concat(",").concat(commandNumber).concat(",").concat(String.valueOf(sequence)).concat(",").concat(time).concat("#");
        // 设置免打扰协议
        Command command = new Command();
        command.setImei(imei);
        command.setContent(content);
        command.setCommandNumber(commandNumber);
        command.setCmd(Constants.SET_NO_DISTURB_TIME);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setSequence(sequence);
        return command;
    }
}
